#include "DealerPreFlop.h"

DealerPreFlop::DealerPreFlop(Dealer *dealer)
{
	nbPartieAvantNouvelleDistribution = dealer->nbPartieAvantNouvelleDistribution;
	compteurDePartie = dealer->compteurDePartie;
	isDistribute = dealer->isDistribute;
	cards = dealer->cards;
	playerMemory = dealer->playerMemory;
	//Comme c'est un remplacement je supprime l'objet passé en paramètre
	delete dealer;
}
DealerPreFlop::DealerPreFlop() {
	nbPartieAvantNouvelleDistribution = NBGAME;
	compteurDePartie = nbPartieAvantNouvelleDistribution;
	isDistribute=true;
}
void DealerPreFlop::distribution(Player & player1, Player & player2)
{
	if( compteurDePartie == nbPartieAvantNouvelleDistribution || compteurDePartie <= 0)
	{
		cout << "------------------------------------------------------" << endl;
		cout << "------------Start DealerPreFlop::distribution-----------" << endl;
		//Distrubution paire d'AS
		if(PLAYER_ONE_HAND_AS)
		{
			player1.hand[0] = Game::getGame()->cards[1];
			player1.hand[1] = Game::getGame()->cards[14];
			Game::getGame()->cards.erase(1);
			Game::getGame()->cards.erase(14);
		}
		//Distribution aléatoire
		else
		{
			// 1ère carte joueur 1 /
			int v1 = (rand()% (Game::getGame()->cards.size()-1) )+1;
			int b1=1;
			for( map <int,Card>::iterator ii=Game::getGame()->cards.begin(); ii!=Game::getGame()->cards.end(); ++ii)
			{
				if(b1==v1)
				{
					Card c= (Card)(*ii).second;
					player1.hand[0] = c;
					cout << "card 1 choisie (player1) : "<< c.toString().toStdString() << endl;
					Game::getGame()->cards.erase(ii);
					break;
				} else b1++;

			}

			// 2nd carte joueur 1 /
			int v2 = (rand()% (Game::getGame()->cards.size()-1) )+1;

			int b2=1;
			for( map <int,Card>::iterator ii=Game::getGame()->cards.begin(); ii!=Game::getGame()->cards.end(); ++ii)
			{
				if(b2==v2)
				{
					Card c = (Card)(*ii).second;
					player1.hand[1] = c;
					Game::getGame()->cards.erase(ii);
					cout << "card 2 choisie (player1) : "<< c.toString().toStdString() << endl;
					break;
				} else b2++;
			}
			Game::getGame()->cards.erase(v2);
		}
		// 1ère carte joueur 2/
		int v3 = (rand()% (Game::getGame()->cards.size()-1) )+1;
		int b3=1;
		for( map <int,Card>::iterator ii=Game::getGame()->cards.begin(); ii!=Game::getGame()->cards.end(); ++ii)
		{
			if(b3==v3)
			{
				Card c = (Card)(*ii).second;
				player2.hand[0] = c;
				Game::getGame()->cards.erase(ii);
				cout << "card 1 choisie (player2) : " << c.toString().toStdString() << endl;
				break;
			} else b3++;
		}

		// 2nd carte joueur 2 /
		int v4 = (rand()% (Game::getGame()->cards.size()-1) )+1;
		int b4=1;
		for( map <int,Card>::iterator ii=Game::getGame()->cards.begin(); ii!=Game::getGame()->cards.end(); ++ii)
		{
			if(b4==v4)
			{
				Card c = (Card)(*ii).second;
				player2.hand[1] = c;
				Game::getGame()->cards.erase(ii);
				cout << "card 2 choisie (player2) : "<< c.toString().toStdString() << endl;
				break;
			} else b4++;
		}

		cout << "1" << endl;
		playerMemory.clear();
		cout << "2" << endl;
		playerMemory[1] = player1;
		cout << "3" << endl;
		playerMemory[2] = player2;

		cout << "------------Finish DealerPreFlop::distribution-----------" << endl;
		cout << "-------------------------------------------------------" << endl;
	}
}
